package com.gumbou.mis.pos.service.impl;

import com.gumbou.mis.pos.entity.PosOrderItem;
import com.gumbou.mis.pos.mapper.PosOrderItemMapper;
import com.gumbou.mis.pos.service.PosOrderItemService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (PosOrderItem)表服务实现类
 *
 * @author makejava
 * @since 2021-11-09 20:16:29
 */
@Service("posOrderItemService")
public class PosOrderItemServiceImpl implements PosOrderItemService {
    @Resource
    private PosOrderItemMapper posOrderItemMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param orderItemId 主键
     * @return 实例对象
     */
    @Override
    public PosOrderItem queryById(Integer orderItemId) {
        return this.posOrderItemMapper.queryById(orderItemId);
    }

    /**
     * 分页查询
     *
     * @param posOrderItem 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PosOrderItem> queryByPage(PosOrderItem posOrderItem, PageRequest pageRequest) {
        long total = this.posOrderItemMapper.count(posOrderItem);
        return new PageImpl<>(this.posOrderItemMapper.queryAllByLimit(posOrderItem, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param posOrderItem 实例对象
     * @return 实例对象
     */
    @Override
    public PosOrderItem insert(PosOrderItem posOrderItem) {
        this.posOrderItemMapper.insert(posOrderItem);
        return posOrderItem;
    }

    /**
     * 修改数据
     *
     * @param posOrderItem 实例对象
     * @return 实例对象
     */
    @Override
    public PosOrderItem update(PosOrderItem posOrderItem) {
        this.posOrderItemMapper.update(posOrderItem);
        return this.queryById(posOrderItem.getOrderItemId());
    }

    /**
     * 通过主键删除数据
     *
     * @param orderItemId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer orderItemId) {
        return this.posOrderItemMapper.deleteById(orderItemId) > 0;
    }
}
